package com.handinfo.game;

import java.io.DataInputStream;
import java.io.IOException;

import javax.microedition.lcdui.Graphics;

import com.handinfo.engine.AbstractGameScreen;
import com.handinfo.uimenu.UIManager;
import com.handinfo.uimenu.UIPalette;
import com.handinfo.uimenu.UITools;
import com.handinfo.util.Tools;

public class GameCarbon {
	private String m_name = null;//副本名称
	private String m_key = null;//副本key
	private int m_lv = 0;//副本等级
	private byte m_day_yet = 0;//普通每日进入次数
	private byte m_day_max = 0;//普通每次进入上限
//	public byte m_extra_yet = 0;//额外每日进入次数
//	public byte m_extra_max = 0;//额外每日进入上限
	private byte m_status = 0;//当前状态
	private String m_info;//介绍说明
	private int m_gun_x;//滚动的位移
	private int m_info_width;//说明文字的长度
	
	public final byte STATUS_JOIN = 0;//参加
	public final byte STATUS_LINE_UP = 1;//排队中
	public final byte STATUS_ADD = 2;//增次
	public final byte STATUS_NO_INTO = 5;//不可进入
	
	private final String[] STATUS_DESCRIBE = {"立即参加", "排队中", "增加次数", "次数耗尽", "队长控制", "不可进入"};
	
	public void drawCarbon(Graphics g, int x, int y, int w, int h) {
		g.setColor(UIManager.getPaletteColor(UIPalette.COLOR_WORD_NOS));
		int tempX = x + UITools.GAP_LEFT;
		int tempY = y + UITools.GAP_UP;
		g.drawString(m_name + "(" + m_lv + "级)", tempX, tempY, Tools.LEFT_TOP);
		if( m_info == null ){
			m_info = "";
		}
		tempY += UITools.H_SINGLE_BAR;
		String temp = "介绍 : ";
		int info_widh = AbstractGameScreen.s_font.stringWidth(temp);
		g.drawString( temp,tempX, tempY, Tools.LEFT_TOP);
		g.setClip(tempX+info_widh, tempY, w-(info_widh + 6), AbstractGameScreen.FONT_H);
		g.drawString( m_info,tempX+info_widh-m_gun_x, tempY, Tools.LEFT_TOP);
		g.setClip(0, 0, AbstractGameScreen.SCREEN_WIDTH, AbstractGameScreen.SCREEN_HEIGHT);
		g.drawString("副本状态 : " + m_day_yet + "/" + m_day_max + "次 "+ STATUS_DESCRIBE[m_status], x + UITools.GAP_LEFT,
				y + (UITools.H_SINGLE_BAR << 1) + UITools.GAP_UP, Tools.LEFT_TOP);
		
		g.setColor(Tools.WHITE);
		g.drawRect(x, y, w, h);
	}
	
	public void gun(int i,int curIndex,int MaxWith){
		if( i== curIndex ){
			if( m_info_width > MaxWith ){
				if( m_gun_x < m_info_width){
					m_gun_x ++;
				}else{
					m_gun_x = -MaxWith;
				}
			}
		}else{
			m_gun_x = 0;
		}
	}
	
	public void read(DataInputStream dis) throws IOException {
			m_key = dis.readUTF();
			m_name = dis.readUTF();
			m_lv = dis.readInt();
			m_day_yet = dis.readByte();
			m_day_max = dis.readByte();
			m_status = dis.readByte();
			//解屏1
			m_info = dis.readUTF();
			if(m_info != null){
				m_info_width = AbstractGameScreen.s_font.stringWidth(m_info);
			}
	}
	
	public void updateStatus(byte status) {
		m_status = status;
	}
	public byte getStatus() {
		return m_status;
	}
	public String getKey() {
		return m_key;
	}
	public int getLv() {
		return m_lv;
	}
	public void read(int i) {
		m_name = "万宝阁" + (i + 1);
		m_lv = (byte)(20 + i);
		m_day_yet = (byte)(0 + i);
		m_day_max = (byte)(1 + i);
	}
}
